package com.salesmanager.core.modules.cms.aliyun;

import com.aliyun.oss.OSSClient;
import com.salesmanager.core.constants.Constants;
import com.salesmanager.core.utils.CoreConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by Liutong on 9/13/15.
 */
@Component
public class OSSClientFactory {

    private static OSSClient ossClient = null;
    @Autowired
    private CoreConfiguration coreConfiguration;

    public OSSClient getInstance(){
        if (ossClient == null){
            synchronized (this){
                if (ossClient == null){
                    ossClient = new OSSClient(coreConfiguration.getProperty(Constants.ALIYUN_ENDPOINT),
                            coreConfiguration.getProperty(Constants.ALIYUN_ACCESS_ID),
                            coreConfiguration.getProperty(Constants.ALIYUN_ACCESS_KEY));
                }
            }
        }
        return ossClient;
    }
}
